<template>
  <div class="tabbar">
    <ul>
      <li v-for="(item, index) in routerList" :key="index" @click="switchTab(item.path)">
        <span :class="[{ active: route.path.includes(item.path) }]">{{ item.title }}</span>
      </li>
    </ul>
  </div>
</template>

<script setup>
import { ref, defineComponent } from 'vue'
import { useRouter, useRoute } from 'vue-router'
const tabbar = defineComponent({
  name: 'Tabbar',
  // 组件的其他选项...
})
let router = useRouter()
let route = useRoute()

const routerList = ref([
  {
    path: '/home',
    title: '首页',
    icon: 'icon-shouye',
  },
  {
    path: '/live',
    title: '直播',
    icon: 'icon-fenlei',
  },
  {
    path: '/shopping',
    title: '商城',
    icon: 'icon-gouwuche',
  },
  {
    path: '/my',
    title: '我的',
    icon: 'icon-gouwuche',
  },
])
//路由跳转
const switchTab = (path) => {
  router.push(path)
}
</script>

<style>
.tabbar {
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 999;
  width: 100%;
  height: 1.25rem;
  background-color: white;
}

.tabbar ul {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 100%;
  height: 100%;
  border-top: 1px solid rgb(226, 226, 226);
}

.tabbar ul li {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.tabbar ul li span {
  font-size: 0.45rem;
  /* color: rgb(102, 102, 102); */
}

.active {
  color: red;
}
</style>
